<div class="row animate fadeIn">
    <form class="form-horizontal" id="edit-uom-form">
    <div class="ibox-title" style="border:none;"><h5 style="color: #00afef"><i>Edit</i></h5>
        <div class="ibox-tools">    
             <button class="btn btn-primary btn-sm save-btn-tab" id="submit-uom">Save</button>
             <a id="cancel_edit" class="btn btn-sm btn-outline btn-info cancel-btn-tab" type="submit">Cancel</a>
        </div>
     </div>
     <div class="ibox-content">
        <?php foreach ($result as $uom ) { ?>
        <input type="hidden" name="e_company_id" value="<?php echo $uom->company_id; ?>">
        <input type="hidden" name="e_uom_id" value="<?php echo $uom->uom_id; ?>">
             <div class="form-group">
                <label class="col-lg-2 control-label">UOM Code</label>
                <div class="col-lg-2">
                    <input type="text" class="form-control" name="e_uom_code" value="<?php echo $uom->uom_code; ?>" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-lg-2 control-label">Name</label>
                <div class="col-lg-3">
                    <input type="text" class="form-control" id="e_uom_n" name="e_uom_name" value="<?php echo $uom->uom_name; ?>">
                </div>
            </div>
            <div class="form-group"><label class="col-lg-2 control-label">Enable</label>
                <div class="col-lg-1">
                    <input type="checkbox" class="i-checks" id="e_uom_cb" name="e_uom_enabler" value="ok" <?php echo($uom->enable_flag == 'Y' ? 'checked' : ''); ?> >
                </div>
            </div>
           <?php } ?> 
        </form>
    </div>
 </div> 
 <script>
    $(document).ready(function(){
        $('#edit-uom-form').data('serialize',$('#edit-uom-form').serialize());
        $('.i-checks').iCheck({
                    checkboxClass: 'icheckbox_square-green',
                    radioClass: 'iradio_square-green',
        }); 
        $('#edit-uom-form').validate({
            rules : {
                e_uom_name: {
                    required: true,
                    lettersonly: true
                }
            },
            submitHandler: function(form){
                    $.ajax({
                        type: "POST",
                        url: "<?php echo base_url($this->session->userdata('forajax').'/update_uom'); ?>",
                        data: $('#edit-uom-form').serialize(),
                        dataType: 'json',
                        success: function(data){
                           if(data[0].error != 1){
                            console.log("nka edit nku");
                                notifymsg("success",". . .Units of Measure Updated Successfully");
                                close_edit(); active_search();
                           }else{
                            notifymsg("danger",data[0].msg);
                           }
                        },
                        complete: function() {

                        },
                        beforeSend: function(){
                           
                        }
                    });
                 }
             });

        function alert_cancel(){
            if($('#edit-uom-form').serialize()!=$('#edit-uom-form').data('serialize')){
                // Form has changed!!!
                swal({
                                          title: "Are you sure?",
                                          text: "Your work will not be save",
                                          type: "warning",
                                          showCancelButton: true,
                                          confirmButtonColor: "#DD6B55",
                                          confirmButtonText: "Leave",
                                          cancelButtonText: "Stay",
                                          closeOnConfirm: true,
                                          closeOnCancel: true },
                                      function (isConfirm) {
                                          if (isConfirm) {
                                            swal("success");
                                              close_edit(); active_search();
                                              notifymsg("hide","hide");
                                          } else {
                                              swal("Cancelled");
                                          }
                                      });
                }else{
                close_edit(); active_search();
                notifymsg("hide","hide");
            }
        }
        $('#cancel_edit').click(function(){
            alert_cancel();
        });

       $('#editX').click(function(){
            alert_cancel();
       });
    });
 </script>